package 双指针.快乐数;

public class HappyNum {
    public static void main(String[] args) {
        Solution so = new Solution();
        System.out.println(so.isHappy(2));
    }
}
class Solution {
    public boolean isHappy(int n) {
        int slow = fun(n);
        int fast = fun(fun(n));
        while(slow != fast){
            slow = fun(slow);
            fast = fun(fun(fast));
        }
        return slow == 1;
    }
    public static int fun(int n) {
        int sum = 0;
        while(n > 0){
            sum+=Math.pow(n % 10,2);
            n/=10;
        }
        return sum;
    }
}